package end.util.customtag;


import java.io.IOException;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

import end.constant.Const;



/**
 * 
 * PermitTag.java 2016-7-13
 * 
 * Copyright zhaocj Inc. All rights reserved. Love Me Like Love Justin Bieber
 */
@SuppressWarnings("serial")
@Component
public class PermissionTag extends TagSupport {
	private final static Logger log = LogManager
			.getLogger(PermissionTag.class);

	private String url = null;
	private String jsMethod = null;
	private String img = null;
	private String value = null;
	private String css = null;

    public String getCss() {
		return css;
	}

	public void setCss(String css) {
		this.css = css;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getJsMethod() {
		return jsMethod;
	}

	public void setJsMethod(String jsMethod) {
		this.jsMethod = jsMethod;
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public int doEndTag() throws JspException {
		return super.doEndTag();
	}

	@SuppressWarnings("static-access")
	@Override
	public int doStartTag() throws JspException {
		HttpSession session = this.pageContext.getSession();
		String rights = (String)session.getAttribute(Const.SESSION_USER_RIGHTS);
		log.info("得到了userRightsStr"+rights+"----------");
		JspWriter jspWriter = pageContext.getOut();
		System.out.println(url);
		if(rights.contains(url)){
			try {
				jspWriter.print("<a href = '" + url + "' class = 'regular'>"
						+ value + "</a>");
			} catch (IOException e) {
				e.printStackTrace();
			}
            return super.EVAL_BODY_INCLUDE;			
		}
		return super.SKIP_BODY;
	}
}
